package com.agriculture.mapper;

import com.agriculture.entity.AddressBook;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapperOne extends BaseMapper<AddressBook> {
    /**
     * 根据 id 查询地址
     * @param id
     * @return
     */
    @Results({
            @Result(column = "area_code", property = "areaCode"),
            @Result(column = "area_code", property = "tblArea",
                    one = @One(select = "com.agriculture.mapper.AddressBookMapper.selectByCode"))
    })
    @Select("select * from address_book where id = #{id}")
    AddressBook getAddById(Long id);

    /**
     * 多表查询用户默认地址
     * @param userId
     * @return
     */
    @Results({
            @Result(column = "area_code", property = "areaCode"),
            @Result(column = "area_code", property = "tblArea",
                    one = @One(select = "com.agriculture.mapper.AddressBookMapper.selectByCode"))
    })
    @Select("select * from address_book where user_id = #{userId} and is_default = 1")
    AddressBook getDefAddById(Long userId);

    /**
     * 查询指定用户的全部地址
     * @param userId
     * @return
     */
    @Results({
            @Result(column = "area_code", property = "areaCode"),
            @Result(column = "area_code", property = "tblArea",
                    one = @One(select = "com.agriculture.mapper.AddressBookMapper.selectByCode"))
    })
    @Select("select * from address_book where user_id = #{userId} and is_deleted = 0 order by update_time desc")
    List<AddressBook> getList(Long userId);





}
























